package puf.m2.automaton;

/**
 * A Letter is an element of the alphabet A, which is can be read
 * back-and-forth.
 */
public class Letter {
    /** Label that describe value the character */
    private char letter;
    /** Is this character an inverse? */
    private boolean bar;

    public Letter(char letter) {
        this(letter, false);
    }

    public Letter(char letter, boolean isBar) {
        this.letter = letter;
        this.bar = isBar;
    }

    /**
     * Toggle the value of bar.
     * If bar is TRUE then change it to FALSE and vice versa.
     */
    public void toggleBar() {
        bar = !bar;
    }

    /**
     * Describe how to compare 2 characters.
     */
    @Override
    public boolean equals(Object other) {
        if (other == null || !(other instanceof Character))
            return false;
        Letter otherChar = Letter.class.cast(other);
        return (letter ==  otherChar.letter && this.bar == otherChar.bar);
    }

    @Override
    public String toString() {
        return (bar ? "~" : "" + letter);
    }

    /*------ GETTER/SETTER -----*/

    public char letter() {
        return letter;
    }

    public void setLetter(char letter) {
        this.letter = letter;
    }

    public boolean bar() {
        return bar;
    }

    public void setBar(boolean isBar) {
        this.bar = isBar;
    }
}
